package com.hlf.modules.api.controller;

import com.hlf.common.constants.Constants;
import com.hlf.common.utils.ReturnResult;
import com.hlf.common.validator.Assert;
import com.hlf.modules.merchant.bank.entity.BranchBank;
import com.hlf.modules.merchant.bank.service.BankCardBinService;
import com.hlf.modules.merchant.bank.service.BranchBankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 银行信息
 * Created by Administrator on 2017/10/19.
 */
@RestController
@RequestMapping("/api/bank")
@Api("银行信息")
public class ApiBankController {

    @Autowired
    private BranchBankService branchBankService;
    @Autowired
    private BankCardBinService bankCardBinService;

    /**
     * 获取支行列表
     *
     * @param bankCardNo
     * @return
     */
    @PostMapping("/branchList")
    @ApiOperation(value = "获取支行列表", notes = "获取支行列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "token", value = "token", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "bankCardNo", value = "银行卡号", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "provinceCode", value = "省级地区代码", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "cityCode", value = "市级地区代码", required = true),
    })
    public ReturnResult selectByProviceAndCity(String bankCardNo, String provinceCode, String cityCode) {
        Assert.isBlank(bankCardNo,"银行卡号不能为空!");
        Assert.isBlank(provinceCode,"省级地区代码不能为空!");
        Assert.isBlank(cityCode,"市级地区代码不能为空!");

        BranchBank branchBank = new BranchBank();
        branchBank.setProvinceCode(Long.parseLong(provinceCode));
        branchBank.setCityCode(Long.parseLong(cityCode));
        String bankOrgCode = bankCardBinService.getBankOrgCodeByCardNo(bankCardNo);
        branchBank.setBankOrgCode(bankOrgCode);
        List<BranchBank> branchBanks = branchBankService.selectByProviceAndCity(branchBank);
        return ReturnResult.ok().put(Constants.DEFAULT_RESULT_NAME,branchBanks);
    }


    @PostMapping("/getBankOrgCode")
    public String getBankOrgCode(String bankCardNo) {
        return bankCardBinService.getBankOrgCodeByCardNo(bankCardNo);
    }

}

